﻿using System.Drawing;
using UIKit;
using Foundation;
using MvvmCross.Binding.BindingContext;
using MvvmCross.iOS.Views;
using CoreGraphics;
using TipCalc.core.ViewModels;

namespace TipCalc.UI.Touch.Views
{
    public class  TipCalcViewController : MvxViewController
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

           // #region 创建6个控件

            var SubTotalTextField = new UITextField();
            var GenerositySlider = new UISlider();
            var TipLabel = new UILabel();

            var subTotalInfoLabel = new UILabel { Text = "总消费：" };
            var generosityInfoLabel = new UILabel { Text = "比例：" };
            var tipInfoLabel = new UILabel { Text = "小费：" };

            //#region 将6个控件加入到View中，并固定位置
            View.AddSubview(subTotalInfoLabel);
            subTotalInfoLabel.Frame = new CGRect(60, 100, 200, 30);

            View.AddSubview(SubTotalTextField);
            SubTotalTextField.Frame = new CGRect(60, 140, 200, 30);
            SubTotalTextField.KeyboardType = UIKeyboardType.NumberPad;
            SubTotalTextField.BorderStyle = UITextBorderStyle.RoundedRect;

            View.AddSubview(generosityInfoLabel);
            generosityInfoLabel.Frame = new CGRect(60, 180, 200, 30);

            View.AddSubview(GenerositySlider);
            GenerositySlider.Frame = new CGRect(60, 220, 200, 30);
            GenerositySlider.MaxValue = 100;
            GenerositySlider.MinValue = 0;


            View.AddSubview(tipInfoLabel);
            tipInfoLabel.Frame = new CGRect(60, 260, 200, 30);

            View.AddSubview(TipLabel);
            TipLabel.Frame = new CGRect(60, 300, 200, 30);

            //#region 数据绑定
            this.CreateBinding(SubTotalTextField).To<TipViewModel>(vm => vm.SubTotal).Apply();
            this.CreateBinding(GenerositySlider).To<TipViewModel>(vm => vm.Generosity).Apply();
            this.CreateBinding(TipLabel).To<TipViewModel>(vm => vm.Tip).Apply();

            // Perform any additional setup after loading the view
        }
    }
}